package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.bo.goods.GoodsCatBO;
import com.ymk.core.code.cmd.GoodsCmdCode;
import com.ymk.core.enums.goods.GoodsCatStatusEnum;
import com.ymk.service.IGoodsCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class GoodsCatPostCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        GoodsCatBO reqData = super.getData(sign, GoodsCatBO.class);
        reqData.setStatus(GoodsCatStatusEnum.NORMAL.getStatus());
        super.setCreatedData(sign,reqData);
        this.goodsCatService.post(reqData);

        return respSign;
    }

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        GoodsCatBO reqData = super.getData(sign, GoodsCatBO.class);

        reqData.setStatus(GoodsCatStatusEnum.NORMAL.getStatus());
        reqData.setMchId(sign.getMchId());
        super.setCreatedData(sign,reqData);

        this.goodsCatService.post(reqData);

        return respSign;
    }

    @Override
    public CmdSign executeStore(HttpServletRequest request, CmdSign sign) throws Exception {
        return super.executeStore(request, sign);
    }

    @Override
    public String getCmdCode() {
        return GoodsCmdCode.GOODS_CAT_POST;
    }

    @Autowired
    private IGoodsCatService goodsCatService;
}